package cn.edu.sjtu.stap.cfg.internal;

import java.util.*;

import org.aspectj.ajdt.internal.core.builder.*;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.*;

import cn.edu.sjtu.stap.cfg.*;
import cn.edu.sjtu.stap.cfg.builder.*;
import cn.edu.sjtu.stap.cg.builder.*;

import cn.edu.sjtu.stap.sdg.internal.*;

/**
 * 
 */
public privileged aspect InterModuleCfgBuilderAdapter {
    declare precedence : InterSdgBuilderAdapter,InterModuleCfgBuilderAdapter;

    after(AjBuildConfig b) : AsmFetcher.asmFetcherPc(b) {
        try {
            ICfgBuilder cfgBuilder = Initializer.getCfgBuilder();
            ICgBuilder cgBuilder = Initializer.getCgBuilder();

            Map<AbstractMethodDeclaration, ControlFlowGraph> graphs = cfgBuilder.getIntraModuleCfgs();
//            Initializer.out.writeLine("IntraCFGs Start:------------------------------------------");
//            Initializer.out.writeLine("**********************************************************");
//            Initializer.out.writeIntraModuleCfg(graphs);

            cfgBuilder.buildInterModuleCfg(cgBuilder.getResult(), cfgBuilder.getIntraModuleCfgs(), cgBuilder
                    .getProgramEntries());

            graphs = cfgBuilder.getInterModuleCfgs();
            Initializer.out.writeLine("InterCFG Starts:------------------------------------------");
            Initializer.out.writeLine("**********************************************************");
            Initializer.out.writeInterModuleCfg(graphs);
        } catch (Throwable t) {
            System.err.println("Caught unexpected exception in Inter CFG construction!");
            t.printStackTrace();
        }
    }
}
